gsk: Pass the appropriate value for the n_quads argument
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 4 Aug 2016 18:14:51 +0000 (19:14 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 18 Oct 2016 10:49:12 +0000 (11:49 +0100)
Instead of passing the size of the buffer, we should pass the number of
quads; we know what the size of a single quad structure is, so we can do
the multiplication internally when creating the VAO.

This allows us to print the quads for debugging purposes.

gsk/gskgldriver.c
gsk/gskglrenderer.c

index 443a0ad840ac93333bc7ed2472419bf2bab5e4ca..a6345259c75a58f46faf0d9c0d9aa2b4bb3e91b5 100644 (file)
@@ -365,7 +365,7 @@ gsk_gl_driver_create_vao_for_quad (GskGLDriver   *driver,
 
   glGenBuffers (1, &buffer_id);
   glBindBuffer (GL_ARRAY_BUFFER, buffer_id);
-  glBufferData (GL_ARRAY_BUFFER, n_quads, quads, GL_STATIC_DRAW);
+  glBufferData (GL_ARRAY_BUFFER, sizeof (GskQuadVertex) * n_quads, quads, GL_STATIC_DRAW);
 
   glEnableVertexAttribArray (position_id);
   glVertexAttribPointer (position_id, 2, GL_FLOAT, GL_FALSE,
@@ -387,6 +387,21 @@ gsk_gl_driver_create_vao_for_quad (GskGLDriver   *driver,
   v->uv_id = uv_id;
   g_hash_table_insert (driver->vaos, GINT_TO_POINTER (vao_id), v);
 
+#ifdef G_ENABLE_DEBUG
+  if (GSK_DEBUG_CHECK (OPENGL))
+    {
+      int i;
+      g_print ("New VAO(%d) for quad[%d] : {\n", v->vao_id, n_quads);
+      for (i = 0; i < n_quads; i++)
+        {
+          g_print ("  { x:%.2f, y:%.2f } { u:%.2f, v:%.2f }\n",
+                  quads[i].position[0], quads[i].position[1],
+                  quads[i].uv[0], quads[i].uv[1]);
+        }
+      g_print ("}\n");
+    }
+#endif
+
   return vao_id;
 }
 
index 1e3dcd2e3d93abc94a664e84a71d3dfe3a1a557d..7d16ee1f12cd3deb547eac49cb193b4e61f2b301 100644 (file)
@@ -716,7 +716,7 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
       gsk_gl_driver_create_vao_for_quad (self->gl_driver,
                                          item.render_data.position_location,
                                          item.render_data.uv_location,
-                                         sizeof (GskQuadVertex) * N_VERTICES,
+                                         N_VERTICES,
                                          vertex_data);
   }